Struct Vs Class When To Use Which · How it works
1 min readRapid overview
How it works
_TODO: explain the mental model._
🧩 Real-World Example (HFM context)
If you’re processing millions of tick messages per second:
- Use a
struct(orreadonly struct) for individual ticks (lightweight, immutable). - Use a
classfor services and entities that manage state, likeOrderBook,TradeSession, orCacheManager.
Example:
readonly struct Tick
{
public string Symbol { get; init; }
public double Bid { get; init; }
public double Ask { get; init; }
}
class PriceFeedProcessor
{
private readonly List<Tick> _ticks = new();
public void OnTick(Tick tick) => _ticks.Add(tick);
}